
/**
 *	\file
 *	Defines the sun::system_config singleton.
 *	\author Sean Tromans
 */

namespace sun
{

	//
	//	Public Member Functions
	//

	/**
	 *	Add a configuration parameter.
	 *	@param name The unique name of the configuration parameter.
	 *	@param value The value to assign this parameter.
	 *	\throws sun::duplicate_config if the config already existed.
	 *	\author Sean Tromans
	 */
	template < typename TType >
	void system_config::add_param( nmn::hashed_string const & name, TType const & value )
	{
		auto iter = m_params.find( name );
		if ( iter == m_params.end( ) )
		{
			m_params.insert( std::make_pair( name, boost::any( value ) ) );
		}
		else
		{
			throw duplicate_config( name );
		}
	}

	/**
	 *	Retreive the configuration parameter with the given name.
	 *	@param name The unique name of the configuration parameter to find.
	 *	\throws sun::config_not_found if the config does not currently exist within the system.
	 *	\throws boost::bad_any_cast if the parameter was not of type TType.
	 *	\author Sean Tromans
	 */
	template < typename TType >
	TType const & system_config::get_param( nmn::hashed_string const & name )
	{
		auto iter = m_params.find( name );
		if ( iter != m_params.end( ) )
		{
			return boost::any_cast< TType const & >( iter->second );
		}
		else
		{
			throw config_not_found( name );
		}
	}

	//
	//	Private Member Functions
	//
}
